package com.huangliusong;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

import com.google.common.collect.Maps;


public class CountExamplehls2 {
	private static Map<String, Integer> map=Maps.newHashMap();
	private static int threadNum=1;
	private static int clientNum=5000;
	
	public static void main(String[] args) {
		ExecutorService executorService=Executors.newCachedThreadPool();
		final Semaphore semaphore=new Semaphore(threadNum);
		for(int i=0;i<clientNum;i++) {
			executorService.execute(()->{
				try {
					semaphore.acquire();
					func(threadNum);
					semaphore.release();
				} catch (Exception e) {
					System.err.println(e);
				}
			});
		}
		executorService.shutdown();
		System.out.println(map.size());
	}

	private static void func(int threadNum2) {
		map.put(UUID.randomUUID().toString(), threadNum2);
	}
}
